package cong;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cong.Note;
//import cong.Dbconnection;
public class ReceiveNoteServlet extends HttpServlet {
	
	private static final long serialVersionUID = 1L;       
    public ReceiveNoteServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		response.setContentType("UTF-8");		
		String title = request.getParameter("title");
		String content = request.getParameter("content");
		String contact = request.getParameter("contact");
		//判断是否跳转到【成功】
		if(title != null){
			Note note = new Note();
			note.setTitle(title);
			note.setContent(content);
			note.setContact(contact);
			if(new Dbconnection().addNote(note)){		
				response.sendRedirect("Success.jsp");
			}
		}
					
	}
}
